<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>主页面</title>
	<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
	<script type="text/javascript" src="../easyui/jquery-1.6.min.js"></script>
	<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script>
	<STYLE>
	.tablestyle01{background-color:#E1EDF7;}
	.tablestyle01 td{ padding:3px 0px 3px 6px; border-bottom:1px dashed #ACB3B9; font-size:12px;}
	</STYLE>
	
	<script>
		$(function(){
			$(window).resize(function(){
				$("#div_tabs").tabs({width:$(window).width()-$("#div_menu").width(), height:$(window).height()-$("#div_south").height()-$("#div_top").height()-10});
				$("#div_menu").accordion({height:$(window).height()-$("#div_south").height()-$("#div_top").height()-37});
			});
			
			$("#ul_menu_tree").tree({
				onClick:function(node){
					addTab(node);
				}
			});//初始化菜单
			
			initMenuTree();//初始化菜单
			initLoginUserMsg();//初始化登录人信息
		});
		
		/*关闭当前选择的tab页*/
		function removeCurrSelectTab(){
			var tab = $("#div_tabs").tabs("getSelected");
			$("#div_tabs").tabs("close",tab.panel('options').title);
		}
		
		//添加tab页
		function addTab(node){
			if(node!=null && node.attributes!=null && node.attributes.url!=null && node.attributes.url!=''){
				var id = node.id ;
				var url = node.attributes.url;
				var title = node.text;
				var stitle = title.length>12?title.substr(0,12)+"...":title;
				sttile = "<span markid=\""+id+"\">"+stitle+"</span>";//必须的时候缩写
				
				var tabTmp = $("#div_tabs").tabs("getTab",stitle);
				if(tabTmp!=null){//防止打开多个
					$("#div_tabs").tabs("select",stitle);
					return false;
				}
				
				var bj = url.indexOf("?")>-1?"&":"?";
				url += bj+"break_time_number="+new Date().getTime();
				var content = "<iframe src=\""+url+"\" frameborder=\"0\" style=\"width:100%; height: 100%;\"></iframe>";
				var tab = $("#div_tabs").tabs("add",{
					title: stitle,
					content: content,
					closable: true,
					menuId: id,
					mtitle: title
				});	
				$("#div_tabs").tabs("select",stitle);
			}
		}
		
		//初始化功能菜单
		function initMenuTree(){
			$.ajax({
			  type: "POST",
			  url: "menuTree.action",
			  dataType: "json",
			  success: function(json){
			  	var root = json.trees[0];
			  	root.state = "open";
			  	root.children[root.children.length-1].state = "open";
			  	$("#ul_menu_tree").tree("loadData", json.trees);
			  }
			});
		}
		
		//初始化登录信息
		function initLoginUserMsg(){
			$.ajax({
			  type: "POST",
			  url: "userMsg.action",
			  dataType: "json",
			  success: function(json){
			  	var user = json.user;
			  	for(var key in user){
			  		var el = document.getElementById("td_"+key);
			  		if(el != null){
			  			el.innerText = user[key];
			  		}
			  	}
			  }
			});
		}
		
		//用户退出调用
		function userOut(b){
			if(!b){return false;}
			$.ajax({
			  type: "POST",
			  url: "../userOut.action",
			  dataType: "text",
			  success: function(json){
			  	window.location = "../login.html";
			  }
			  ,error: function(a){alert("退出异常");}
			});
		}
		
		//显示帮助面板
		function showHelp(){
			var tab = $("#div_tabs").tabs("getSelected");
			var options = tab.panel("options");
			var menuId = options.menuId;
			if(menuId!=null && menuId != ""){
				$.ajax({
				  type: "POST", url: "help.action", dataType: "json", data: "menuId="+menuId,
				  success: function(json){
				  	if(json.url!=null && json.url!=""){
				  		$("#help_window").window("open");
				  		document.getElementById("iframe_help").src = json.url;
				  	}else{
				  		alert("未查询到可用的帮助");
				  	}
				  }
				});
			}else{
				alert("当前操作功能未配置功能ID");
			}
		}
		
		function alert(msg){
			$.messager.alert("提示",msg);
		}
		
		function show(msg){
			$.messager.show({
				showType: 'show',
				title:"提示",
				msg:msg,
				timeout:3000
			});
		}
		
		function confirm(title, msg, fn){
			$.messager.confirm(title, msg, fn);
		}
		
		//提供给子页面调用登录信息
		function getUserId(){
			return document.getElementById("td_userId").innerText;
		}
		
		//下载调用
		function download(url){
			document.getElementById("iframe_download").src = "FileDownloadServler?tmpFileName="+url+"&1="+new Date();
		}
	</script>
</head>

<body class="easyui-layout">
	<div id="div_top" region="north" border="false" style="height:40px;background-color: #E1EDF7;">
		<iframe id="iframe_download" src="" style="display: none;"></iframe>
		<div align="right">
			<a href="#" onclick="showHelp();return false;">帮助</a>
			&nbsp;&nbsp;|&nbsp;&nbsp;
			<a href="#" onclick="confirm('提示', '确认退出', userOut);return false;">退出</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<div id="help_window" closed="true" closable="false" collapsible="true" resizable="false" title="帮助" class="easyui-window" style="width: 640px; height: 440px;">
				<iframe id="iframe_help" src="" frameborder="0" style="width: 100%; height: 100%;"></iframe>
			</div>
		</div>
	</div>
	<div id="div_menu" region="west" class="easyui-accordion" split="true" title="功能区域" style="width:240px; ">
		<div title="功能菜单" style="width:240px;">
			<ul id="ul_menu_tree" ></ul>
		</div>
		<div id="id_user_msg" title="用户信息" style="width: 100%; font-size: 10px; background-color:#E1EDF7;" >
			<table class="tablestyle01" width="100%">
				<tr>
					<td width="80px;">用户名</td>
					<td id="td_UId">&nbsp;</td>
				</tr>
				<tr>
					<td>名称</td>
					<td id="td_UName">&nbsp;</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="div_tabs" region="center" class="easyui-tabs" >
		<div title="欢迎页面" closable="false"><iframe src="welcome.html" frameborder="0" style="width:100%; height: 100%;"></iframe></div>
	</div>
	<div id="div_south" region="south" border="false" align="center" style="height:50px;background-color: #E1EDF7; padding-top:10px;  ">
		xxxxxxxxx有限公司 <br>
		xxxxxxxx@版权所有<br>
	</div>
</div>
</body>
</html>